<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>淘宝宝短网址</title>
<meta name="description" content="淘宝宝短网址,淘宝短网址,淘宝客短网址, 网址缩短服务,短网址生成,网址二维码" />
<link rel="icon" href="http://www.taobao.com/favicon.ico" type="image/x-icon">
<script src="http://lib.sinaapp.com/js/jquery/1.8/jquery.min.js" >
</script>
<script>
(function($){
	$(function(){	
		var i = $("#urlinput");
		var txt = "输入你想变短的 网址 如(http://www.taobao.com)";

		var blurTimer = false;
		i.focus(function(){
			clearTimeout(blurTimer);
			$(this).removeClass("blur");
			if($(this).val() == txt){
				$(this).val("");
			}
		});

		i.blur(function(){
			if($(this).val() == ""){
				$(this).val(txt);
				$(this).addClass("blur");
			}
		});
		i.blur();

		var expandtimer = false;
		i.keydown(function(){
			clearTimeout(expandtimer);
			
			expandtimer = setTimeout(function(){
				$("#working").show("slow");
				$("#longurl").hide();
				$.post("/d/long",{url: $.trim(i.val())})
				.success(function(data){
					var longurl = data["long"];
					var wanted = data["wanted"];
					if(longurl && $.trim(i.val()) == wanted){
						var _longurl = $("#longurl");
						var a = $('<a href="javascript:;">点我展开短网址 <em>'+ wanted + '</em></a>');
						a.click(function(){ i.val(longurl);});
						_longurl.children().remove();
						_longurl.append(a);
						_longurl.show('fast');
					}
				})
				.error(function(){
				})
				.complete(function() {
					$("#working").hide();
				});
				;
			}, 800);
		});

		var o = $("#urloutput");
		o.click(function(){
			$(this).select();
		});
		
		$("#work").click(function(){
			$("#error").hide();
			$("#longurl").hide();
			if(i.val() != txt){
				$("#working").show("slow");
				$(this).attr("disabled","disabled");
				$.post("/d/save",{url: i.val()})
				.success(function(data){
					var key = data["key"];
					var err = data["err"] ? data["err"] : "发生错误 请重试";
					$("#error").text(err);
					if(key){
						i.animate({
							width:"150px"
						}, 
						{
							complete: function(){
								o.val("http://tao.bb/" + key);
								$("button").toggle();
								$("input").toggle();
							}
						});
					}else{
						$("#error").show("fast");
					}
				})
				.error(function(){
					$("#error").text("网络错误");
					$("#error").show("fast");
				})
				.complete(function() {
					$("#working").hide();
					$("#work").removeAttr("disabled");
					
				});
				;
			}else{
				if(!blurTimer){
					blurTimer = setInterval(function(){i.toggleClass("blur");}, 100);
					setTimeout(function(){
						clearTimeout(blurTimer);
						blurTimer = false;
						i.addClass("blur");
					}, 1000);
				}
			}
		});
		$("#work").removeAttr("disabled");

		$("#more").click(function(){
			$(this).attr("disabled","disabled");
			$("input").toggle();
			i.animate({
				width:"473px"
			}, 
			{
				complete: function(){
					$("button").toggle();
					$("#more").removeAttr("disabled");
				}
			});
		});

		(function(){
			var wanted = location.pathname.replace( /^\/+|\/+$/g, '' );
			if (wanted){
				$("#error").text('您访问的网址：1.不存在 2.不安全(如钓鱼) 3.传播禁止的内容 而无法访问 ').show();
			}
		})();

		$("#favorite").click(function(){
			var url = window.location;
			var title = document.title;
			try {
				if (window.sidebar) {
					window.sidebar.addPanel(title, url, "");
				} else {
					window.external.addFavorite(url, title);
				}
			} catch(b) {
				alert('您的浏览器不支持自动收藏，请按 Ctrl+D 手动收藏！');
			}
		});

	})
})(jQuery);
</script>
</head>
<body>

<style>

.inputbox{
border:5px solid #FF7800;
font:14px/18px verdana,tahoma,arial,宋体,sans-serif;
height:14px;
padding:7px 4px;
vertical-align:middle;
margin-top: 20px; margin-bottom: 20px;
}

.blur{
color:#BABABA;
}

#urlinput {
width:473px;
}

#urloutput {
width:150px;
}
#body{
text-align: center;
margin-top: 100px;
}

#footer{
text-align: center;
margin-top: 100px;
}

button {
background:url("http://img05.taobaocdn.com/tps/i5/T1nAlrXohtXXXXXXXX-300-389.png") no-repeat scroll 0 -149px transparent;
border:medium none;
color:#FFFFFF;
cursor:pointer;
font-size:14px;
font-weight:700;
height:30px;
width:93px;
}
</style>

<div id="body">
	<div>
		<img src="http://img01.taobaocdn.com/tps/i1/T1trD5XllgXXaur3jj-180-65.png" alt="tao.bb" >
	</div>
	<input id="urlinput" value="" autocomplete="off" autofocus="true" class="inputbox blur" alt="" />
	<input id="urloutput" value="" readonly="readonly" autocomplete="off" autofocus="true" class="inputbox" style="display:none" alt=""/><br />
	<button id="work">tao.bb</button><button id="more" style="display:none">再来一个</button><br />
	<p id="working" style="display:none"><img src="http://img01.taobaocdn.com/tps/i1/T1cKm3XkRpXXXXXXXX-48-48.gif" alt="loading" /></p>
	<p id="error" style="color:red; display:none">发生错误 请重试</p>
	<p id="longurl" style="display:none"></p>
	<div id="qrcode" style="margin-top: 20px;display:none"><img src="" style="width:120px;height:120px"/></div>

</div>
<div id="footer">
<span><a href="http://tao.bb/Y06rW" target="_blank">获取源代码</a></span> | <span><a href="mailto:farmer1992@gmail.com" >联系作者</a></span>
</div>
<div id="favorite" style="cursor:pointer; background:url(http://img02.taobaocdn.com/tps/i2/T1T.ekXkxXXXXXXXXX-32-90.png);width:32px;height:90px;position:fixed; _position:absolute; right:5px; top:150px; _bottom:auto;  _top:expression((documentElement.scrollTop+150)+'px');">	
</div>

</body>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-36067927-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</html>
